package com.woniu.mgr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.mgr.controller.form.ModifyVenueForm;
import com.woniu.mgr.model.Venue;
import com.woniu.mgr.dao.VenueDao;
import com.woniu.mgr.service.VenueService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.mgr.util.BeanCopyUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 场馆表 服务实现类
 * </p>
 *
 * @author Silas
 * @since 2023-02-15
 */
@Service
public class VenueServiceImpl extends ServiceImpl<VenueDao, Venue> implements VenueService {
    @Resource
    private VenueDao venueDao;

    @Override
    public void modify(ModifyVenueForm modifyVenueForm) {
        Venue venue = BeanCopyUtil.copyObject(modifyVenueForm, Venue.class);
        updateById(venue);
    }

    @Override
    public Page<Venue> query(String condition, Integer current, Integer size) {
        //配置分页片段
        Page<Venue> page = new Page<>(current == null ? 1 : current, size == null ? 4 : size);
        //配置queryWrapper
        QueryWrapper<Venue> queryWrapper = new QueryWrapper<>();
        //判断condition是否为空，为空则findAll,不为空则条件查询
        if (!"".equals(condition) || condition != null) {
            //配置queryWrapper查询条件
            queryWrapper.eq("name", condition)   //条件查询
                    .or().like("venue_id", condition)
                    .or().like("address", condition)   //模糊查询
                    .or().eq("phone", condition)
                    .or().eq("account_name", condition)
                    .or().eq("longitude", condition)
                    .or().eq("latitude", condition)
                    .or().eq("state", condition)
                    .or().eq("email", condition);

        }
//生成分页
        Page<Venue> venuePage = venueDao.selectPage(page, queryWrapper);


        return venuePage;
    }
}
